/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MetricsRetriever;

import MetricsRetriever.RetrieverComponents.*;
import DataStructures.ProjectInformation;
import General.FileManager;
import General.Globals;

/**
 *
 * @author Manuel
 */
public class ObjectiveRetrieverFactory extends RetrieverFactory{
    private Parser parser;
    private ProjectInformation projectInfo;
    private Retriever retriever;
    private FileManager fManager;

    public ObjectiveRetrieverFactory(Parser p,String link) {
        parser = p;
        projectInfo = parser.getProjectInformation(link);
        fManager = new FileManager(projectInfo.getName());
    }

    public Retriever getRetriever(){
        retriever = new ConcreteRetriever(projectInfo);
        this.composeRetriever();
        return retriever;
    }

    protected void composeRetriever(){
        retriever.setMetricsMeasurer(this.choseMetricsManager());
        retriever.setRepositoryManager(this.choseRepositoryManager());
        retriever.setBugManager(this.choseBugManager());
        retriever.setMatcher(this.choseMatcher());
    }

    protected MetricsManager choseMetricsManager() {
        if(projectInfo.getMainLanguage().toLowerCase().equals("java")){
            projectInfo.setLanguageChosen("java");
            return (new JavaManager(projectInfo,fManager));
        }
        else if(projectInfo.getMainLanguage().toLowerCase().equals("cplusplus")){
            projectInfo.setLanguageChosen("cplusplus");
            return (new CppManager(projectInfo,fManager));
        }
        /*else if (projectInfo.isOfLanguage("python"))
            return (new PythonManager());
          else if (projectInfo.isOfLanguage("cplusplus"))
            return (new CPPManager());
         */
        return null;
    }

    protected RepositoryManager choseRepositoryManager() {
        if(projectInfo.getRepositoryType() == Globals.SVN)
            return (new SVNManager(projectInfo,fManager));
        /*elsse if (projectInfo.getLanguage == Globals.CVS)
            return (new CVSManager());
          else if (projectInfo.getLanguage == Globals.GIT)
            return (new GITManager());
         */
        return null;

    }

    protected BugManager choseBugManager() {
        if(projectInfo.getUrl().contains("code.google.com"))
            return (new GCBugManager(projectInfo.getName()));

        else if(projectInfo.getUrl().contains("sourceforge.net")){
            if(projectInfo.getBugLink() != null)
            return (new SFBugManager(projectInfo.getBugLink()));

        }


        return null;
    }

      protected Matcher choseMatcher() {
        if(projectInfo.getUrl().contains("code.google.com"))
            return (new GCMatcher());

        else if(projectInfo.getUrl().contains("sourceforge.net")){
            return (new SFMatcher());

        }
        return null;
    }

}
